# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Serge Ziryukin <ftrvxmtrx@gmail.com>

pkgname=pdcurses
pkgver=3.9
pkgrel=2
pkgdesc='Cross-platform curses implementation'
arch=(loong64 x86_64)
url='https://pdcurses.org/'
license=(GPL)
makedepends=(sdl sdl2 libxpm xaw3d)
source=("$pkgname-$pkgver.tgz::https://github.com/wmcbrine/PDCurses/archive/$pkgver.tar.gz")
options=(staticlibs)
sha256sums=('590dbe0f5835f66992df096d3602d0271103f90cf8557a5d124f693c2b40d7ec')

build() {
  export CFLAGS="$CFLAGS -fPIC"

  # X11
  cd PDCurses-$pkgver/x11
  ./configure --prefix=/usr --enable-widec --with-xaw3d --with-x
  make
  gcc $CFLAGS $LDFLAGS -shared -o libXCurses.so *.o

  # SDL1
  cd ../sdl1
  make
  gcc $CFLAGS $LDFLAGS -shared -o pdcurses.so *.o

  # SDL2
  cd ../sdl2
  make
  gcc $CFLAGS $LDFLAGS -shared -o pdcurses2.so *.o
}

package() {
  # X11
  cd PDCurses-$pkgver/x11
  make prefix="$pkgdir/usr" install
  cd ..
  install -Dm644 curspriv.h "$pkgdir/usr/include/curspriv.h"

  # SDL1, compatible with asciiportal
  install -Dm644 sdl1/pdcsdl.h "$pkgdir/usr/include/pdcsdl.h"
  install -Dm644 sdl1/pdcurses.so "$pkgdir/usr/lib/libpdcurses.so"

  # SDL2, incompatible with asciiportal
  install -Dm644 sdl2/pdcsdl.h "$pkgdir/usr/include/pdcsdl2.h"
  install -Dm644 sdl2/pdcurses2.so "$pkgdir/usr/lib/libpdcurses2.so"

  # Only keep shared libraries
  rm -f "$pkgdir/usr/lib/libXCurses.a"
}

# getver: raw.githubusercontent.com/wmcbrine/PDCurses/master/curses.h
# vim: ts=2 sw=2 et:
